<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class College extends Model
{
    protected $table = 'college';

    public $timestamps = false;

    public $fillable = [
        "college_id","college_name","introduction","english_name","province_id",
        "province_name","city","address","enroll_website","official_url","department",
        "nature","education_level","create_year","rank","college_phone","recruit_phone",
        "category","characteristic","research_teaching","postgraduate_proportion",
        "boys_proportion","scholarship","college_scenery","logo_url","public_address",
        "canteen_dormitory","college_affiliation","employment_proportion","school_id",
        "content","status","retry_count","last_error",'is_yikao','yk_type'
    ];

    protected $guarded = [];

    protected $casts = [
        'college_scenery' => 'array',
        // 'employment_proportion' => 'array'
    ];

    /**
     * 标记为已采集
     */
    public function markAsCrawled()
    {
        $this->status = 1;
        $this->save();
    }

    /**
     * 记录错误信息
     */
    public function recordError(string $error)
    {
        $this->last_error = $error;
        $this->retry_count += 1;
        $this->save();
    }

    public function characteristic() {
        $this->hasMany('App\Models\Characteristic','college_id','college_id');
    }
}
